﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Peekaboo2008.dao;
using Peekaboo2008.model;

namespace Peekaboo2008.view
{
    public partial class FormNhaCungCap : Form
    {
        public FormNhaCungCap()
        {
            InitializeComponent();
            FormNhaCungCapLoad();
        }

        public void FormNhaCungCapLoad()
        {
            DataTable dt = KhachHangDAO.NhaCungCap_GetAll();
            dgvNCC.DataSource = dt;
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {
            FormNhaCungCap formNCC = this;
            FormChiTietNhaCungCap formChiTietNCC = new FormChiTietNhaCungCap(ref formNCC);
            formChiTietNCC.ShowDialog();
        }

        private void dgvNCC_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            FormNhaCungCap formNCC = this;
            KhachHangModel model = new KhachHangModel();
            model.Id = dgvNCC.CurrentRow.Cells["ID"].Value.ToString();
            model.Ten = dgvNCC.CurrentRow.Cells["Ten"].Value.ToString();
            model.MaKhuVuc = dgvNCC.CurrentRow.Cells["maKhuVuc"].Value.ToString();
            model.MaNhomKhachHang = dgvNCC.CurrentRow.Cells["maNCC"].Value.ToString();
            model.DiaChi = dgvNCC.CurrentRow.Cells["diaChi"].Value.ToString();
            model.Tel = dgvNCC.CurrentRow.Cells["Tel"].Value.ToString();
            model.Email = dgvNCC.CurrentRow.Cells["Email"].Value.ToString();
            model.Fax = dgvNCC.CurrentRow.Cells["Fax"].Value.ToString();
            model.SoTaiKhoan = dgvNCC.CurrentRow.Cells["soTaiKhoan"].Value.ToString();
            model.MaSoThue = dgvNCC.CurrentRow.Cells["maSoThue"].Value.ToString();
            model.NganHang = dgvNCC.CurrentRow.Cells["nganHang"].Value.ToString();
            model.GhiChu = dgvNCC.CurrentRow.Cells["ghiChu"].Value.ToString();
            FormChiTietNhaCungCap formChiTietNCC = new FormChiTietNhaCungCap(model, ref formNCC);
            formChiTietNCC.ShowDialog();
        }

        private void FormNhaCungCap_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormNhaCungCap_KeyDown);
        }

        private void FormNhaCungCap_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                tsbThem.PerformClick();
            }
            else if (e.KeyCode == Keys.F4)
            {
                tsbThoat.PerformClick();
            }
        }

        private void tsbThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
